package com.ptmall.app.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ptmall.app.R;
import com.ptmall.app.bean.HomePageTuijianBean;
import com.ptmall.app.bean.ShopCarBean;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.ui.activity.CateListActivity;
import com.ptmall.app.ui.activity.GoodDetilActivity;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.view.NoScrollGridViewDirver;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by zjh on 2016/9/23.
 * 新品推荐
 */
public class GoodimgreAdapter extends RecyclerView.Adapter<GoodimgreAdapter.ViewHolder> {

    private Activity mActivity;
    private List<ShopCarBean> mDataList = new ArrayList();

    public GoodimgreAdapter(Activity mActivity) {
        this.mActivity = mActivity;
    }

    public void bind(List<ShopCarBean> mData) {
        this.mDataList = mData;
    }

    public interface Click{
        void addcarimg(ImageView iv, String id, String num);

    }

    public Click click;

    public void setClick(Click click) {
        this.click = click;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_goodimg, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, int position) {
        ShopCarBean bean = mDataList.get(position);
        GlideUtil.showImg(mActivity,bean.list_img,viewHolder.img);
        viewHolder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, GoodDetilActivity.class);
                intent.putExtra("id",bean.productId);
                mActivity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView img;

        public ViewHolder(View view) {
            super(view);

            img = (ImageView) view.findViewById(R.id.goodimg);

        }
    }


}
